package com.huanxiao.base.net.exception;

import com.huanxiao.base.common.bean.EventMessage;
import com.huanxiao.base.constant.EventConst;
import com.huanxiao.base.net.ErrorCode;
import com.huanxiao.util.ToastHelper;

import org.greenrobot.eventbus.EventBus;

/**
 * Created by paul on 16/10/18.
 */

public class RespException extends RuntimeException {

    private int errCode = -1;

    private String msg;
    public RespException(int errCode, String msg) {
        super(msg);
        this.errCode = errCode;
        this.msg = msg;


        if (errCode== ErrorCode.EXPIRED_TOKEN.getCode()){
            ToastHelper.showMessage(ErrorCode.EXPIRED_TOKEN.getDesc());
            EventBus.getDefault().post(new EventMessage(EventConst.EVENT_LOGOUT));

        }else {
            ToastHelper.showMessage(msg);
        }

    }

    public void setErrCode(int errCode) {
        this.errCode = errCode;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getErrCode() {
        return errCode;
    }
}
